<template>
  <div class="shopList" style="margin:24px 24px 0 24px;">
    <div class="disFlex Flex-middle search shadow">
      <Form
        :model="formItem"
        :label-width="120"
        style="display:flex;flex-direction:row;align-items:center;flex-flow:wrap;height: 100px;"
        class="searchForm"
      >
        <FormItem label="职位名称">
          <Input v-model="formItem.jobName" placeholder="请输入账号名称" style="width:180px"></Input>
        </FormItem>
        <FormItem label="企业名称">
          <Input v-model="formItem.companyName" placeholder="请输入账号名称" style="width:180px"></Input>
        </FormItem>
        <FormItem label="查看状态">
          <Select v-model="formItem.applyStatus" style="width:150px">
            <Option value>全部</Option>
            <Option :value="1">待查看</Option>
            <Option :value="2">已查看</Option>
          </Select>
        </FormItem>
        <FormItem label="沟通状态">
          <Select v-model="formItem.contactStatus" style="width:150px">
            <Option value>全部</Option>
            <Option :value="1">待沟通</Option>
            <Option :value="2">已沟通</Option>
            <Option :value="3">不合适</Option>
          </Select>
        </FormItem>

        <!-- <FormItem label="时间查询类型"></FormItem> -->
        <FormItem label="时间查询类型">
          <Row>
            <Col span="5">
              <Select v-model="formItem.searchType" style="width:100px">
                <Option value="timeCreate">投递时间</Option>
                <Option value="timeUpdate">沟通时间</Option>
              </Select>
            </Col>
            <Col span="8">
              <DatePicker type="date" placeholder="请选择开始时间" v-model="formItem.searchDataBegin"></DatePicker>
            </Col>
            <Col span="2" style="text-align: center">-</Col>
            <Col span="8">
              <DatePicker type="date" placeholder="请选择结束时间" v-model="formItem.searchDataFinish"></DatePicker>
            </Col>
          </Row>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchData">搜索</Button>
        </FormItem>
      </Form>
    </div>
    <TableList
      :columns="columns"
      :data="data"
      :page="page"
      :total="pageTotal*pageNum"
      :pageNum="pageNum"
      newOne="导出"
      tableTitle="投递记录"
      @newOneFn="newOne"
      @changePage="changePage"
    ></TableList>
  </div>
</template>

<script>
import TableList from "@/components/consumer/tableList";
import { DeliverResume } from "api/recuit/user";
import Config from "@/config";
export default {
  name: "",
  data() {
    return {
      formItem: {
        companyName: "",
        jobName: "",
        searchType: "timeCreate",
        searchDataBegin: "",
        searchDataFinish: "",
        isExportCSV: "",
        applyStatus: "",
        contactStatus: ""
      },
      gender: ["未知", "男", "女"],
      educationArr: [
        "学历不限",
        "小学",
        "初中",
        "中专",
        "高中",
        "大学专科",
        "大学本科",
        "硕士",
        "博士",
        "博士后",
        "其它"
      ],
      experienceArr: [
        "经验不限",
        "无经验",
        "1年",
        "2年",
        "3年",
        "4年",
        "5年",
        "6年",
        "7年",
        "8年",
        "9年",
        "10年"
      ],
      columns: [
        {
          title: "简历姓名",
          key: "worker_nickname",
          width: 160
        },
        {
          title: "基本信息",
          key: "action",
          width: 220,
          render: (h, params) => {
            return h(
              "span",
              {
                style: {
                  marginLeft: "15px"
                }
              },
              this.gender[params.row.worker_gender] +
                "/" +
                (this.jsGetAge(params.row.worker_birthday) == 0
                  ? "年龄未知/"
                  : this.jsGetAge(params.row.worker_birthday) + "岁/") +
                this.educationArr[params.row.worker_education] +
                "/" +
                this.experienceArr[params.row.worker_experience]
            );
          }
        },
        {
          title: "投递职位",
          key: "jobTitle",
          width: 180,
          render: (h, params) => {
            return h("span", params.row.jobTitle || params.row.position_title);
          }
        },
        {
          title: "投递企业",
          key: "title",
          width: 180
        },
        {
          title: "查看状态",
          key: "apply_status",
          width: 120,
          render: (h, params) => {
            return h(
              "span",
              params.row.apply_status == 1 ? "待查看" : "已查看"
            );
          }
        },
        {
          title: "沟通状态",
          key: "contact_status",
          width: 120,
          render: (h, params) => {
            switch (params.row.contact_status) {
              case 1:
                return h("span", "待沟通");
                break;
              case 2:
                return h("span", "已沟通");
                break;
              case 3:
                return h("span", "不合适");
                break;
              default:
                break;
            }
          }
        },
        {
          title: "投递时间",
          key: "time_create",
          width: 180
        },
        {
          title: "沟通时间",
          key: "time_update",
          width: 180
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "middle"
                  },
                  style: {
                    margin: "0 2px"
                  },
                  on: {
                    click: () => {
                      this.$router.push({
                        name: "resumeEdit",
                        params: { worderId: params.row.worker_id }
                      });
                    }
                  }
                },
                "查看简历"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "middle"
                  },
                  style: {
                    margin: "0 2px"
                  },
                  on: {
                    click: () => {
                      this.$router.push({
                        name: "postDetail",
                        params: { jobId: params.row.job_id }
                      });
                    }
                  }
                },
                "查看职位"
              )
              //   h(
              //     "Button",
              //     {
              //       props: {
              //         type: "primary",
              //         size: "middle"
              //       },
              //       style: {
              //         margin: "0 2px"
              //       },
              //       on: {
              //         click: () => {
              //           this.$router.push({
              //             name: "editShop",
              //             params: { companyId: params.row.worker_id }
              //           });
              //         }
              //       }
              //     },
              //     "查看企业"
              //   )
            ]);
          }
        }
      ],

      data: [],
      page: 0,
      pageNum: 5, //显示条数
      pageTotal: 0 //页面总数
    };
  },
  components: {
    TableList
  },

  mounted() {
    this.user_id = localStorage.getItem("user_id");
    this.is_super_user = localStorage.getItem("is_super_user");
    this.getData();
  },

  methods: {
    //切换页面
    changePage(data) {
      let { page } = data;
      this.page = --page;
      this.getData();
    },
    //条件查询
    searchData() {
      this.page = 0;
      this.getData();
    },
    newOne() {
      this.formItem.isExportCSV = true;
      this.getData();
    },
    //获取数据
    getData() {
      let page = this.page;
      let formItem = this.formItem;
      let dataList = new Object();
      if (this.formItem.isExportCSV) {
        dataList.page = 1;
      } else {
        dataList.page = ++page;
      }
      //获取查询条件
      for (let i in formItem) {
        dataList[i] = formItem[i];
      }
      if (this.formItem.isExportCSV) {
        //正在走导出
        var urlParam = "?";
        for (let key in dataList) {
          urlParam = urlParam + key + "=" + dataList[key] + "&";
        }
        let openUrl = Config.recuitUrl + "/Job/deliverResume" + urlParam;
        window.open(openUrl.substring(0, openUrl.length - 1));
      } else {
        DeliverResume(dataList).then(res => {
          let { jobApplyList, page, jobApplyCount } = res;
          this.data = jobApplyList;
          this.page = Number(page.page);
          this.pageTotal = page.pageTotal;
        });
      }
    },
    jsGetAge(strBirthday) {
      let returnAge;
      // 根据生日计算年龄（"1995-09-25"）
      //以下五行是为了获取出生年月日，如果是从身份证上获取需要稍微改变一下
      let strBirthdayArr = strBirthday.split("-");
      let birthYear = strBirthdayArr[0];
      let birthMonth = strBirthdayArr[1];
      let birthDay = strBirthdayArr[2];

      let d = new Date();
      let nowYear = d.getFullYear();
      let nowMonth = d.getMonth() + 1;
      let nowDay = d.getDate();

      if (nowYear == birthYear) {
        returnAge = 0; //同年 则为0岁
      } else {
        let ageDiff = nowYear - birthYear; //年之差
        if (ageDiff > 0) {
          if (nowMonth == birthMonth) {
            let dayDiff = nowDay - birthDay; //日之差
            if (dayDiff < 0) {
              returnAge = ageDiff - 1;
            } else {
              returnAge = ageDiff;
            }
          } else {
            let monthDiff = nowMonth - birthMonth; //月之差
            if (monthDiff < 0) {
              returnAge = ageDiff - 1;
            } else {
              returnAge = ageDiff;
            }
          }
        } else {
          returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
        }
      }
      return returnAge; //返回周岁年龄
    }
  }
};
</script>

<style scoped lang="less">
/*表头标题*/
.table-header-title {
  height: 100%;
  padding: 0 18px;
  box-sizing: border-box;
}

/*表头提示图标*/
.table-header-icon {
  font-size: 20px;
  margin-left: 10px;
}

/*弹窗标题*/
.alert-title {
  margin-top: 10px;
}

/*搜索*/
.search {
  padding: 18px;
  box-sizing: border-box;
  background: #fff;
  margin-bottom: 24px;
}

/*搜索下拉*/
.search-select {
  min-width: 128px;
  width: 128px;
  margin-right: 15px;
}

/*搜索输入框*/
.search-input {
  margin-right: 15px;
  top: 0;
}

.search-button {
  /* width: 80px;
    min-width: 80px; */
  margin-left: 15px;
}
.timeSpan {
  margin: 0 15px;
}
.detailTable::-webkit-scrollbar {
  width: 15px;
}
.detailTable tr {
  width: 700px;
}
.searchForm {
  .ivu-form-item {
    margin-bottom: 0;
  }
}
</style>
